package com.ruanyun.modular.admin.controller;

import com.ruanyun.base.pojo.page.LayuiPageInfo;
import com.ruanyun.base.shiro.ShiroUser;
import com.ruanyun.modular.admin.entity.TCommitReport;
import com.ruanyun.modular.admin.model.params.TCommitReportParam;
import com.ruanyun.modular.admin.service.TCommitReportService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.ruanyun.sys.core.shiro.ShiroKit;
import freemarker.template.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 报告提交表控制器
 *
 * @author zs
 * @Date 2021-04-28 15:32:10
 */
@Controller
@RequestMapping("/tCommitReport")
public class TCommitReportController extends BaseController {

    private String PREFIX = "/tCommitReport";

    @Autowired
    private TCommitReportService tCommitReportService;

    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2021-04-28
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/tCommitReport.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2021-04-28
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/tCommitReport_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2021-04-28
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/tCommitReport_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2021-04-28
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TCommitReportParam tCommitReportParam) {
        return this.tCommitReportService.add(tCommitReportParam);
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2021-04-28
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TCommitReportParam tCommitReportParam) {
        return this.tCommitReportService.update(tCommitReportParam);
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2021-04-28
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TCommitReportParam tCommitReportParam) {
        return this.tCommitReportService.updateDelFlagById((long)tCommitReportParam.getId());
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2021-04-28
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TCommitReportParam tCommitReportParam) {
        TCommitReport detail = this.tCommitReportService.getById(tCommitReportParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zs
     * @Date 2021-04-28
     */

    @RequestMapping("/list")
    @ResponseBody
    public LayuiPageInfo list(TCommitReportParam tCommitReportParam) {
        return this.tCommitReportService.findPageBySpec(tCommitReportParam);
    }

    /**
     * 启用
     *
     * @author zs
     * @Date 2021-04-28
     */

    @RequestMapping("/enable")
    @ResponseBody
    public ResponseData enable(@RequestParam Long id) {
        return this.tCommitReportService.enableById(id);
    }

    /**
     * 禁用
     *
     * @author zs
     * @Date 2021-04-28
     */

    @RequestMapping("/disable")
    @ResponseBody
    public ResponseData disable(@RequestParam Long id) {
        return this.tCommitReportService.disableById(id);
    }


    /**
     * 提交报告
     *
     * @author zs
     * @Date 2021-04-28
     */

    @RequestMapping("/commitReport")
    @ResponseBody
    public ResponseData commitReport(@RequestParam Integer companyId) {
        return this.tCommitReportService.commitReport(companyId);
    }

    /**
     * 退回报告
     *
     * @author zs
     * @Date 2021-04-28
     */

    @RequestMapping("/returnReport")
    @ResponseBody
    public ResponseData returnReport(@RequestParam Integer id) {

        //获取当前用户角色列表
        ShiroUser user = ShiroKit.getUserNotNull();
        List<Long> roleList = user.getRoleList();
        if ( roleList.get(0) != 1) {
            return ResponseData.error("该用户不是管理员 无法退回报告");
        }
        return this.tCommitReportService.returnReport(id);
    }



}


